package com.example.hospital.controller.api;

import com.example.common.util.core.controller.BaseController;
import com.example.common.util.core.resultbody.AjaxResult;
import com.example.hospital.service.DepartmentService;
import com.example.hospital.service.HospitalService;
import com.example.hospital.service.HospitalSetService;
import com.example.hospital.service.ScheduleService;
import com.example.model.domain.entity.hospital.Hospital;
import com.example.model.domain.entity.hospital.Schedule;
import com.example.model.vo.hospital.ScheduleOrderVo;
import com.example.model.vo.order.SignInfoVo;
import com.example.model.vo.hospital.DepartmentVo;
import com.example.model.vo.hospital.HospitalQueryVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author juzipi
 * @Date 2021/7/12 18:36
 * @Info 这是前台医院管理
 */
@Api(tags = "前台医院管理")
@RestController
@RequestMapping("api/hospital/hospital")
public class HospitalApiController extends BaseController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService hospitalSetService;


    //查询医院列表分页
    @ApiOperation("查询医院列表分页")
    @GetMapping("page/{pageNum}/{pageSize}")
    public AjaxResult getHospitalPage(@PathVariable("pageNum") Integer pageNum,
                                   @PathVariable("pageSize") Integer pageSize,
                                   HospitalQueryVo hospitalQueryVo){
        PageInfo<Hospital> hospitals = hospitalService.getHospitalPage(pageNum, pageSize, hospitalQueryVo);
        return AjaxResult.success(hospitals);
    }


    //根据医院名称查询
    @ApiOperation("根据医院名称查询医院集合")
    @GetMapping("get/{hosname}")
    public AjaxResult getHospitalList(@PathVariable("hosname") String hosname){
        List<Hospital> list = hospitalService.getHospitalByHosname(hosname);  //模糊查询 可能返回多个，用list接收
        return AjaxResult.success(list);
    }


    //根据医院编号获取科室列表
    @ApiOperation("根据医院编号获取科室列表")
    @GetMapping("department/{hoscode}")
    public AjaxResult getDepartment(@PathVariable("hoscode") String hoscode){
        List<DepartmentVo> list = departmentService.getDepartmentTree(hoscode);
        return AjaxResult.success(list);
    }


    //根据医院编号获取预约挂号详情
    @ApiOperation(value = "根据医院编号获取预约挂号详情")
    @GetMapping("get/hospitalDetail/{hoscode}")
    public AjaxResult getHospitalDetail(@PathVariable("hoscode") String hoscode){
        Map<String,Object> map = hospitalService.getHospitalDetailByHoscode(hoscode);
        return AjaxResult.success(map);
    }


    //获取可预约排班数据
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/get/bookingScheduleRule/{pageNum}/{pageSize}/{hoscode}/{depcode}")
    public AjaxResult getBookingSchedule(
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize,
            @PathVariable String hoscode,
            @PathVariable String depcode
    )
    {
        Map<String, Object> bookingScheduleRulePage = scheduleService.getBookingScheduleRulePage(pageNum, pageSize, hoscode, depcode);
        return AjaxResult.success(bookingScheduleRulePage);
    }


    @ApiOperation(value = "获取排班具体数据")
    @GetMapping("auth/get/scheduleList/{hoscode}/{depcode}/{workDate}")
    public AjaxResult getScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleDetails = scheduleService.getScheduleDetails(hoscode, depcode, workDate);
        return AjaxResult.success(scheduleDetails);
    }


    //根据排班id获取排班数据
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("get/schedule/{scheduleId}")
    public AjaxResult getSchedule(@PathVariable("scheduleId") String scheduleId){
        Schedule schedule = scheduleService.getScheduleByScheduleId(scheduleId);
        return AjaxResult.success(schedule);
    }


    //根据排班id获取预约下单数据
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/get/scheduleOrderVo/{scheduleId}")
    public AjaxResult getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
       ScheduleOrderVo scheduleOrderVo = scheduleService.getScheduleOrderVoById(scheduleId);
       return AjaxResult.success(scheduleOrderVo);
    }


    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/get/sign/{hoscode}")
    public AjaxResult getHospitalSignByHoscode(@PathVariable("hoscode") String hoscode) {
        SignInfoVo signInfoVo = hospitalSetService.getSignInfoByHoscode(hoscode);
        return AjaxResult.success(signInfoVo);
    }


}
